package com.example.tests;

import static org.testng.Assert.assertEquals;

import java.util.Collections;
import java.util.List;

import org.testng.annotations.Test;

import com.example.fw.GroupHelper;

public class GroupCreationTests extends TestBase
{
	@Test(dataProvider = "randomValidGroupGenerator")
	public void testGroupCreationWithValidData(GroupData group) throws Exception
	{
		app.navigationTo().page("groups");
		
		//save old state
		GroupHelper groupHelper = app.getGroupHelper();
		List<GroupData> oldList = groupHelper.getGroups();
		
		//actions
		groupHelper
			.initGroupCreation()
			.fillGroupForm(group)
			.submitCreation();
		
		app.navigationTo().returnToPage("group page");
		
		//save new state
		List<GroupData> newList = groupHelper.getGroups();
		
		//compare states
		oldList.add(group);
		Collections.sort(oldList);
		assertEquals(newList, oldList);
	}
}
